package com.acdc.device.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.acdc.device.domain.MeterDevice;
import com.acdc.device.service.IMeterDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电能表管理Controller
 * 
 * @author ruoyi
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/device/device")
public class MeterDeviceController extends BaseController
{
    @Autowired
    private IMeterDeviceService meterDeviceService;

    /**
     * 查询电能表管理列表
     */
    //@PreAuthorize("@ss.hasPermi('device:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeterDevice meterDevice)
    {
        startPage();
        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(meterDevice);
        return getDataTable(list);
    }

    /**
     * 导出电能表管理列表
     */
    @PreAuthorize("@ss.hasPermi('device:device:export')")
    @Log(title = "电能表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeterDevice meterDevice)
    {
        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(meterDevice);
        ExcelUtil<MeterDevice> util = new ExcelUtil<MeterDevice>(MeterDevice.class);
        util.exportExcel(response, list, "电能表管理数据");
    }

    /**
     * 获取电能表管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('device:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(meterDeviceService.selectMeterDeviceById(id));
    }

    /**
     * 新增电能表管理
     */
    @PreAuthorize("@ss.hasPermi('device:device:add')")
    @Log(title = "电能表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeterDevice meterDevice)
    {
        return toAjax(meterDeviceService.insertMeterDevice(meterDevice));
    }

    /**
     * 修改电能表管理
     */
    @PreAuthorize("@ss.hasPermi('device:device:edit')")
    @Log(title = "电能表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeterDevice meterDevice)
    {
        return toAjax(meterDeviceService.updateMeterDevice(meterDevice));
    }

    /**
     * 删除电能表管理
     */
    @PreAuthorize("@ss.hasPermi('device:device:remove')")
    @Log(title = "电能表管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(meterDeviceService.deleteMeterDeviceByIds(ids));
    }

    /**
     * 重置IoT模块
     */
    @PreAuthorize("@ss.hasPermi('device:device:edit')")
    @Log(title = "电能表管理", businessType = BusinessType.UPDATE)
    @PutMapping("/resetIotModule/{meterDeviceId}")
    public AjaxResult resetIotModule(@PathVariable Long meterDeviceId)
    {
        return toAjax(meterDeviceService.resetIotModule(meterDeviceId));
    }
}
